POV-Ray : Newsgroups : povray.general : Help creating a sgn() function : Help creating a sgn() function Server Time
2 Aug 2024 00:15:34 EDT (-0400)
  Help creating a sgn() function  
From: Jo Jaquinta
Date: 3 Mar 2005 11:49:22
Message: <42274012$1@news.povray.org>
Hey Folks,
   I'm trying to create a sgn() function, like in BASIC. Where sgn(x) = 
-1 if x < 0, +1 if x > 0 and 0 if x = 0.

First I tried with a function:

#declare sgn = function(xx) { #if (xx<0) -1 #else #if (xx>0) 1 #else 0 
#end #end }

But this dies with a "expected 'numeric expression', undeclared 
identifier 'xx' found instead". I take this to mean you can't use a if 
inside a function.

So I tried with a macro:

#macro sgn(xx)
   #if (xx < 0)
     -1
   #else
     #if (xx > 0)
       1
     #else
       0
     #end
   #end
#end

But this gives me a Parse Error: Expected ')', # found instead on the 
"-1" line.

Am I just being really dumb? This should be a no-brainer...

Cheers,

Jo


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.